<?php

//defined('APP_PATH') or die();
class FrontController {

    protected static $objInstance = null;
    private $controllerPhrase;
    private $controllerCommand;
    private $activePage;

    public static function getInstance() {
        if (is_null(self::$objInstance)) {
            self::$objInstance = new self();
        }

        return self::$objInstance;
    }

    function __construct() {
        //$this->routeMap['users']='users.php';        
    }

    function handleSiteRequest($action=null) {
        $class = ucfirst($_REQUEST['site'] . 'Page');
        if (!class_exists($class)) {
            throw new Exception('Missing ' . $class . ' class.');
        }

        if (!(get_class($this->activePage) == $class)){
            $this->activePage = new $class;
            
        }
        $this->activePage->executeAction($action);
    }

    function parse($param) {
        $start = getTime();
        Propel::init('../model/wincon_mailing_db/build/conf/wincon_mailing_db-conf.php');
        #var_dump($_REQUEST);
        if (isset($_SESSION["UserAccess"])) {
            if (isset($_REQUEST['bk']))
                include '../sendScript.php';
            else
            if (isset($_REQUEST['site'])) {
                $this->handleSiteRequest($_REQUEST['action']);
            } else {
                $layout = Layout::getInstance();
                $layout->executeAction();
            }
        } else {
            $login = new LoginPage();
            if (isset($_REQUEST['login']) && isset($_REQUEST['password']))
                $login->login();
            $login->executeAction();
        }
        $end = getTime();
    }

}

?>
